// run: $exec < input
#include <iostream>
#include <utility>
#include <set>

int n, m;

std::pair<int, int> get(char ch, std::pair<int, int> const & p)
{
	if (ch == 'O') return p;
	else if (ch == '/') return {p.first - 1, p.second + 1};
	else if (ch == '\\') return {p.first - 1, p.second - 1};
	else if (ch == '|') return {p.first - 1, p.second};
	else if (ch == '(') return {p.first - 2, p.second + 1};
	return {p.first - 2, p.second - 1};
}

int main()
{
	std::ios::sync_with_stdio(false);
	int T; std::cin >> T;
	while (T--) {
		std::cin >> n >> m;
		std::set<std::pair<int, int>> all;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++) {
				char ch; std::cin >> ch;
				if (ch == '.') continue;
				all.insert(get(ch, {i, j}));
			}
		std::cout << all.size() << '\n';
	}
}

